// pages/all_error/index.js
const http = require('../../utils/http.js');
import regeneratorRuntime from '../../lib/runtime/runtime'
import {showModal} from '../../utils/asyncwx.js'
Page({

  /**
   * 页面的初始数据
   */
  
  data: {
    uid: null,
    role: null,
    sessionid: null,
    NewsItems: [],
    picker: [],
    index: 0,
    dtype: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
   
    
    
  },
  toadd:function(){
    //页面跳转
    wx.navigateTo({
      url: '../add_error/index',
    })

  },
  async  NewsItemsShow(){
   
    let url = 'news/weeklist/';
    let data = {
      fstid:this.data.dtype
    }
    let res= await http.post(url,data)
    this.setData({
      NewsItems: res.newsList
    })

  },// end of  classifyShow
  PickerChange(e) {
    //类型选择处理
   
    let index0 = e.detail.value
    this.setData({
      index: e.detail.value,
      dtype: this.data.picker[index0].id,
    })
  
    this.NewsItemsShow();   
  },//end of PickerChange
  async fetchtype() {
    //获取发射台类型
    
    let url = 'fst/list';
    let data = {
      uid: this.data.uid
    }
    let res= await http.get(url)
    this.setData({
      picker: res.fstList,
      dtype: res.fstList[0].id,
    });
    this.NewsItemsShow()
   
  },// end of  fetchtype
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    //判断登录状态结束
    this.data.uid = wx.getStorageSync('openid')
    this.data.sessionid = wx.getStorageSync('sessionid')
    this.data.role = wx.getStorageSync('role')
    let sessionid = this.data.sessionid
    let role = this.data.role
    //判断权限
    if (role == 0) {
      //跳转到个人中心
      showModal({content:'权限不足，请先注册您的个人信息!',showCancel:false})
      wx.switchTab({
        url: '/pages/mine/index'
      })
      return false;
    }
    this.fetchtype()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})